package com.mentaleye.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.mentaleye.biz.DictionaryBiz;
import com.mentaleye.biz.TransactionBiz;
import com.mentaleye.enums.TransactionEnums;
import com.mentaleye.util.CommonPage;

@Controller
@RequestMapping(value = "/transaction")
public class TransactionController {

	@Autowired private TransactionBiz transactionBiz;
	@Autowired private DictionaryBiz dictionaryBiz;
	
	@RequestMapping(value = "/{url}/index")
	public ModelAndView index(@PathVariable(value="url") String url){
		ModelAndView view = new ModelAndView("ss/transaction/transactionList");
		Map<Integer,String>   tranObjectMap=dictionaryBiz.queryDictionaryByParent(TransactionEnums.TRANSACTION_OBJECT.getCode());
		Map<Integer, String> tranStateMap = dictionaryBiz.queryDictionaryByParent(TransactionEnums.TRANSACTION_STATE.getCode());
		Map<Integer, String> tranStyleMap = dictionaryBiz.queryDictionaryByParent(TransactionEnums.TRANSACTION_STYLE.getCode());
		Map<Integer, String> tranTypeMap = dictionaryBiz.queryDictionaryByParent(TransactionEnums.TRANSACTION_TYPE.getCode());
		view.addObject("tranObjectMap", tranObjectMap);
		view.addObject("tranStateMap", tranStateMap);
		view.addObject("tranStyleMap", tranStyleMap);
		view.addObject("tranTypeMap", tranTypeMap);
		view.addObject("tranObject", JSONObject.toJSONString(tranObjectMap));
		view.addObject("tranState", JSONObject.toJSONString(tranStateMap));
		view.addObject("tranStyle", JSONObject.toJSONString(tranStyleMap));
		view.addObject("tranType", JSONObject.toJSONString(tranTypeMap));
		view.addObject("urlname", url);
		return view;
	}
	
	@RequestMapping(value = "/transactionListData")
	@ResponseBody
	public String transactionListData(CommonPage commonPage){
		transactionBiz.queryTransactionByMap(commonPage);
		return commonPage.toSHowPage();
	}
}
